{extend name="default/template/base_index" /}


{block name="area_header"}
    <link rel="stylesheet" type="text/css" media="all" href="__CDN__/jquery-datetimepicker/jquery.datetimepicker.css">
    <script type="text/javascript" src="__CDN__/jquery-datetimepicker/jquery.datetimepicker.js"></script>

<link type="text/css" rel="stylesheet" href="__CDN__/select2/4.0.0/css/select2.min.css" />
<script type="text/javascript" src="__CDN__/select2/4.0.0/js/select2.full.js"></script>
<script type="text/javascript" src="__CDN__/select2/4.0.0/js/i18n/zh-CN.js"></script>
{/block}

{block name="area_body"}
    {include file="default/Widget/topbar" /}
    <div class="admin-main container-fluid">
        {include file="default/Widget/left" /}
        <div class="admin-main-content">
            {include file="default/Widget/breadcrumb" /}
            <div class="table-responsive well">
                <div class="h4">
                </div>
                <div class="form-control-static">
                    <form action="{:url('Admin/Message/index')}" method="post" class="form-inline">
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">
                                    <i class="fa fa-calendar"></i>
                                </div>
                                <input type="text" name="startdatetime" id="startdatetime" class="form-control" value="{:toDatetime($startdatetime)}" />
                                <div class="input-group-addon">
                                    <i class="fa fa-long-arrow-right"></i>
                                </div>
                                <input type="text" name="enddatetime" id="enddatetime" class="form-control" value="{:toDatetime($enddatetime)}" />
                                <div class="input-group-addon">
                                    消息类型
                                </div>
                                <select class="form-control" name="msg_type">
                                    <option  value="">=全部=</option>
                                    {volist name="msg_types" id="vo"}
                                        <option {eq name="msg_type" value="$vo.id"}selected{/eq} value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                                <div class="input-group-addon">
                                    消息接收人
                                </div>
                                <div class="form-control" style="background: none;box-shadow: none; padding: 3px;" >
                                <select style="width:220px;padding: 10px 15px;font-size: 15px;line-height: 1.42857143;" id="user_select3" name="to_uid" class="">
                                    <option  value="-2">=不限=</option>
                                </select>
                                </div>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-default btn-sm"><i class="fa fa-search"></i>{:L('BTN_SEARCH')}</button>
                    </form>
                </div>
                <div class="form-control-static">
                    <a href="{:url('Message/bulkDelete')}" class="confirm ajax-post btn btn-danger btn-sm" target-form="selectitem">{:L('BTN_SELECTED_DELETE')}</a>
                    <a href="{:url('Message/send')}" class="btn btn-danger btn-sm" target-form="selectitem">发送消息</a>
                </div>
                <table class="table table-striped table table-hover  table-condensed">
                    <thead>
                    <tr>
                        <th>
                            <input type="checkbox" class="selectall" onclick="myUtils.selectall(this,'.selectitem');" />{:L('SELECT_ALL')}
                        </th>
                        <th>
                            来源
                        </th>
                        <th>
                            接收人
                        </th>
                        <th>
                            标题
                        </th>
                        <th>
                            内容
                        </th>

                        <th>
                            类型
                        </th>

                        <th>
                            摘要
                        </th>
                        <th>
                            发送时间
                        </th>
                        <th>
                            {:L('OPERATOR')}
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td colspan="8" class="text-center">{:L('NO_DATA')}</td>
                        </tr>
                    {/empty}
                    {volist name="list" id="vo"}
                        <tr>
                            <td>
                                <input type="checkbox" value="{$vo.id}" name="ids[]" class="selectitem" />{$vo.id}</td>
                            <td>
                                {eq name="vo['from_id']" value="0"}
                                系统
                                {else/}
                                <a href="{:url('Member/view',array('id'=>$vo['from_id']))}?ret_url=__SELF__" target="_parent">{$vo.from_id}</a>
                                {/eq}
                            </td>
                            <td>
                                {if condition="$vo.to_id eq -2"}所有人{else /}
                                <a target="_self" href="{:url('Member/view',array('id'=>$vo['to_id']))}?ret_url=__SELF__">
                                    <img class="m-avatar" src="{:app\\src\\base\\helper\\ConfigHelper::getAvatarUrl($vo['to_id'],60)}" />
                                    {$vo.to_id}
                                </a>
                                {/if}
                            </td>
                            <td>{$vo.title}</td>
                            <td>
                                <div style="width: 250px; overflow: hidden; text-overflow:ellipsis; white-space:nowrap; ">
                                    {$vo.content}
                                </div>
                            </td>
                            <td>{$vo.name}</td>

                            <td>{$vo.summary}</td>
                            <td>{$vo.send_time|date="Y/m/d H:i:s",###}</td>
                            <td>
                                <a href="{:url(CONTROLLER_NAME .'/delete',array('id'=>$vo['id']))}" class="btn btn-danger btn-sm ajax-get confirm"><i class="fa fa-trash-o"></i> {:L('BTN_DELETE')}</a>
                            </td>
                        </tr>

                    {/volist}
                    </tbody>
                </table>
                <div>
                    {$show}
                </div>
            </div>

        </div>
    </div>
{/block}

{block name="area_footer"}
    <script type="text/javascript">
        $(function() {
            $('#startdatetime').datetimepicker({
                lang: 'ch'
            });
            $('#enddatetime').datetimepicker({
                lang: 'ch'
            });
            $("#user_select3").select2({
                placeholder: "输入用户uid或昵称查询"
                ,
                language: "zh-CN",
                ajax: {
                    url: "{:url('Member/select')}",
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {
                        var queryParameters = {
                            q: params.term
                        };;;;;;;;;

                        return queryParameters;

                    },
                    processResults: function (result, page) {
                        console.log(result);;;;;;;;;
                        if(!result.data){
                            result.data = [];
                            result.data['nodata']="无相关数据";
                        }
                        // parse the results into the format expected by Select2.
                        // since we are using custom formatting functions we do not need to
                        // alter the remote JSON data
                        return {
                            results: result.data
                        };
                    },
                    cache: true
                },
                minimumInputLength: 0,
                templateSelection: function (repo) {
                    return repo.nickname || repo.text;
                },
                templateResult: function (repo) {

                    if (repo.loading) return repo.text;
                    if(repo.nodata) return repo.nodata;
                    var img = "<img src='"+repo.head+"' style='width:30px;height:30px;border-radius: 50%;' />"
                    var markup = '<div>[uid:'+repo.uid+'] '+img+repo.nickname+'</div>';
                    return $(markup);
                },
            });
        })

    </script>
{/block}